﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using WisDom.SmartTMS.Dtos;
using WisDom.SmartTMS.Entities;
using WisDom.SmartTMS.TodoAppService;

namespace WisDom.SmartTMS.Service
{
   public class TodoAppService:ApplicationService,ITodoAppService
    {
        private readonly IRepository<TodoItem, Guid> _repository;
        public TodoAppService(IRepository<TodoItem, Guid> repository) 
        {
            _repository = repository;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public async Task<TodoItemDto> CreateAsync(string text)
        {
            var todoItem = await _repository.InsertAsync(
                new TodoItem { Text = text }
                );
            return new TodoItemDto
            {
                Id = todoItem.Id,
                Text = todoItem.Text,
                TodoTime = todoItem.TodoTime
            };
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task DeleteAsync(Guid id)
        {
           await _repository.DeleteAsync(id);
        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        public async Task<List<TodoItemDto>> GetListAsync()
        {
            var items = await _repository.GetListAsync();
            return items.Select(item => new TodoItemDto
            {
                Id = item.Id,
                Text = item.Text,
                TodoTime = item.TodoTime
            }).ToList();
        }
    }
}
